//
//  ZCWelcomeController.swift
//  weibo
//
//  Created by 张城 on 16/7/22.
//  Copyright © 2016年 张城. All rights reserved.
//

import UIKit


class ZCWelcomeController: UIViewController {

    private lazy var bgImgView: UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    
    private lazy var headImgView: UIImageView = {
        
       let headImg = UIImageView(image: UIImage(named: "avatar_default_big"))
        headImg.zc_setImg((ZCuserAccountViewModel.sharedTools.userAccount?.avatar_large)!, holdImgName: "avatar_default_big")
        headImg.layer.borderColor = UIColor.orangeColor().CGColor
        headImg.layer.borderWidth = 2;
        headImg.layer.cornerRadius = 45
        headImg.layer.masksToBounds = true
        return headImg
    }()
    
    private lazy var label: UILabel = {
       let lab = UILabel()
        lab.text = "立即体验"
        lab.textColor = UIColor.darkGrayColor()
        lab.font = UIFont.systemFontOfSize(18)
        lab.textAlignment = .Center
        lab.alpha = 0
        return lab
    }()
    
    override func loadView() {
        view = bgImgView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }

    func setupUI() {
        view.addSubview(headImgView)
        view.addSubview(label)
        
        headImgView.snp_makeConstraints { (make) in
            make.size.equalTo(CGSizeMake(90, 90))
            make.centerX.equalTo(view.snp_centerX)
            make.top.equalTo(self.view).offset(400)
        }
        
        label.snp_makeConstraints { (make) in
            make.centerX.equalTo(headImgView)
            make.top.equalTo(headImgView.snp_bottom).offset(16)
        }
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        
        headImgView.snp_updateConstraints { (make) in
            //            make.centerX.equalTo(view)
            make.top.equalTo(self.view).offset(100)
        }
        UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
           
            self.view.layoutIfNeeded()
            
            }) { (_) in
                UIView.animateWithDuration(0.25, animations: {
                    
                    self.label.alpha = 1
                    
                    }, completion: { (_) in
                        
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchRootNoti, object: "welcome")
                        
                        
                })
        }
        
        
    }
    
}

















